package com.weiyi.mashangzhu.Roomer.Activity;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Utils.GlideImgManager;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import org.json.JSONException;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AboutActivity extends BaseActivity {

    @BindView(R.id.about_version)
    TextView aboutVersion;
    @BindView(R.id.about_content)
    TextView aboutContent;
    @BindView(R.id.logo)
    ImageView logo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);

        initView();
    }

    //获取关于马上住
    @Override
    public void initView() {
        super.initView();
        LoadingDialog.show(this);
        OkHttpUtils.post().addParams("token", SPUtils.get(this, "token", "") + "").url(API.BaseApi_R + API.Main_AboutUs_Api).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                LoadingDialog.dismiss(AboutActivity.this);
                T.showShort(AboutActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                LoadingDialog.dismiss(AboutActivity.this);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    JSONObject jsonArray = jsonObject.getJSONObject("data");
                    GlideImgManager.glideLoader(AboutActivity.this, API.BaseApi_url + jsonArray.getString("appPic"),R.mipmap.errer, logo);

                    aboutVersion.setText(jsonArray.getString("appVesion") + "");
                    aboutContent.setText(jsonArray.getString("introduce") + "");

                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });


    }


    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
